package ai.yue.open.service.cd.controller;

import ai.yue.library.base.annotation.ApiVersion;
import ai.yue.library.base.ipo.ValidationGroups;
import ai.yue.library.base.view.Result;
import ai.yue.open.service.cd.ipo.DockerImageIPO;
import ai.yue.open.service.cd.service.DockerImageService;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 镜像版本
 *
 * @author yl-yue
 * @since  2023/2/14
 */
@ApiVersion
@AllArgsConstructor
@RestController
@RequestMapping("/auth/{version}/dockerImage")
public class DockerImageController {

    DockerImageService dockerImageService;

    @PostMapping("/insert")
    public Result<?> insert(DockerImageIPO dockerImageIPO) {
        return dockerImageService.insert(dockerImageIPO);
    }

    @DeleteMapping("/deleteById")
    public Result<?> deleteById(Long id) {
        return dockerImageService.deleteById(id);
    }

    @DeleteMapping("/deleteByIds")
    public Result<?> deleteByIds(List<Long> ids) {
        return dockerImageService.deleteByIds(ids);
    }

    @PutMapping("/updateById")
    public Result<?> updateById(@Validated(ValidationGroups.Update.class) DockerImageIPO dockerImageIPO) {
        return dockerImageService.updateById(dockerImageIPO);
    }

    @GetMapping("/page")
    public Result<?> page() {
        // 前端需要传规范的分页参数，框架会自动从request中获取
        return dockerImageService.page();
    }

    @GetMapping("/listAll")
    public Result<?> listAll() {
        return dockerImageService.listAll();
    }

}
